package com.swt.gap.util;

import com.swt.gap.common.ConditionTypeEnum;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 请填写说明
 *
 * @author sx
 * @date 2020/7/9 16:51
 */
public class StringFilter {
    public static Boolean isMatchCondition(String realValue, String configValue, Integer conditionType) {
        boolean retValue = false;
        switch (ConditionTypeEnum.getByCode(conditionType)) {
            case GREATER:
                retValue = Math.abs(Double.parseDouble(realValue)) > Double.parseDouble(configValue);
                break;
            case EQUAL:
                retValue = Math.abs(Double.parseDouble(realValue)) == Double.parseDouble(configValue);
                break;
            case LESS_THAN:
                retValue = Math.abs(Double.parseDouble(realValue)) < Double.parseDouble(configValue);
                break;
            case LIKE:
                retValue = realValue.indexOf(configValue) >= 0;
                break;
            case NOT_LIKE:
                retValue = realValue.indexOf(configValue) < 0;
                break;
            case START_TIME:
                LocalDateTime realTime = LocalDateTime.parse(TimeFormatUtil.transformToStandardFormat(realValue),
                        DateTimeFormatter.ofPattern(TimeFormatUtil.LONG_DATETIME_FORMATTER));
                LocalDateTime configTime = LocalDateTime.parse(TimeFormatUtil.transformToStandardFormat(configValue),
                        DateTimeFormatter.ofPattern(TimeFormatUtil.LONG_DATETIME_FORMATTER));
                retValue = realTime.isAfter(configTime);
                break;
            case END_TIME:
                realTime = LocalDateTime.parse(TimeFormatUtil.transformToStandardFormat(realValue),
                        DateTimeFormatter.ofPattern(TimeFormatUtil.LONG_DATETIME_FORMATTER));
                configTime = LocalDateTime.parse(TimeFormatUtil.transformToStandardFormat(configValue),
                        DateTimeFormatter.ofPattern(TimeFormatUtil.LONG_DATETIME_FORMATTER));
                retValue = realTime.isBefore(configTime);
                break;
            default:
                break;
        }
        return retValue;
    }

}
